package com.rentcars.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rentcars.entity.CarRepair1;
import com.rentcars.mapper.CarRepair1Mapper;
import com.rentcars.service.Repair1Service;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("repair1Service")
public class Repair1ServiceImpl implements Repair1Service {
    @Autowired
    @Getter
    @Setter
    private CarRepair1Mapper carRepair1Mapper;
    @Override
    public int deleteByPrimaryKey(String recordid) {
        return carRepair1Mapper.deleteByPrimaryKey(recordid);
    }

    @Override
    public int insert(CarRepair1 record) {
        return carRepair1Mapper.insert(record);
    }


    @Override
    public CarRepair1 selectByPrimaryKey(String recordid) {
        return carRepair1Mapper.selectByPrimaryKey(recordid);
    }

    @Override
    public int updateByPrimaryKey(CarRepair1 record) {
        return carRepair1Mapper.updateByPrimaryKey(record);
    }

    @Override
    public Page qureyUsersByPage(Map<String, Object> cond) {
        Page page=new Page();
        page.setTotal(carRepair1Mapper.getCount(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);

        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));

        page.setPageNum((int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1)));
        page = PageHelper.startPage(curPageNum, pageSize);
        List list = carRepair1Mapper.getAll(cond);
        return page;
    }
}
